﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RaytracerLib.MathLib;
using TomanuExtensions;
using System.Diagnostics;
using RaytracerLib.Rays;
using RaytracerLib.Lights;

namespace RaytracerLib.ShadowTesters
{
    public class SolidShadowTester : ShadowTester
    {
        public SolidShadowTester(Scene a_scene)
            : base(a_scene)
        {
        }

        public override ColorFloat ShadowTest(Intersection a_source_ray_intersection, ShadowRay a_ray, Light a_light)
        {
            m_scene.Statistics.ShadowTests++;

            if (a_ray.Depth >= m_max_ray_depth)
            {
                m_scene.Statistics.RaysToDepth++;
                return ColorFloat.Black;
            }

            Intersection intersection = m_scene.SpatialSubdivisioner.HitTest(a_source_ray_intersection, a_ray);
            double dist = (a_light.Pos - a_ray.Start).Length;

            if (intersection.Dist < dist)
                return ColorFloat.Black;
            else
                return a_light.Color; 
        }
    }
}
